package com.tong.ft_my.ui;

import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;

import com.tong.ft_my.databinding.FragmentMyBinding;
import com.tong.lib_base.base.AbcFragmentVM;
import com.tong.lib_base.ft_login.model.UserBean;
import com.tong.lib_base.ft_login.service.impl.LoginImpl;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * author:liuzhitong
 * date:2022/3/2
 * description:
 */
public class FragmentMy extends AbcFragmentVM {
    FragmentMyBinding mbinding;
    @Override
    public void initData() {

    }

    @Override
    public void initViews(View view) {
        EventBus.getDefault().register(this);

    }

    @Override
    public View initBinding(@NonNull LayoutInflater inflater) {
        //        viewModel = new ViewModelProvider(this).get(ViewModelFragHome.class);
        mbinding = FragmentMyBinding.inflate(inflater);
        mbinding.setLifecycleOwner(getActivity());
        mbinding.setFragment(this);
//        mbinding.setViewModel(viewModel);
        return mbinding.getRoot();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onReceiveMsg(String message) {
        UserBean userInfo = LoginImpl.getInstance().getUserInfo();
        mbinding.textMessage.setText(userInfo.getUserAccount() + "  "+userInfo.getUserNickName()+"  "+userInfo.getUserPassword());
    }
    public void checkLogin(){
        if(!LoginImpl.getInstance().hasLogin()){
            LoginImpl.getInstance().login(getActivity(),"瞎传的参数");
        }
    }
}
